<?php
$file = dirname( __FILE__ );
$file = substr( $file, 0, stripos( $file, "wp-content" ) );
 
require( $file . '/wp-load.php' );

$cookiespan = time() + 60 * 60 * 24 * 1000;

// userinfo
get_currentuserinfo();
global $wpdb, $user_ID;

// vars
$pid      = intval( $_POST[ 'pid' ] ); // post id
$act      = stripslashes( strip_tags( $_POST[ 'act' ] ) ); 
$cook_str = 'vote' . '_' . $pid;

if( ( $act == 'up' || $act == 'down' ) && $_COOKIE[ "zdm" ][ "$cook_str" ] != 'Y' ) {	
	// current votes num
	$vote_up = $wpdb->get_var( "SELECT vote_up FROM $wpdb->posts WHERE ID = $pid" );
	$vote_down = $wpdb->get_var( "SELECT vote_down FROM $wpdb->posts WHERE ID = $pid" );
	
	if( $act == 'up' ) { 
		$new_votes = $vote_up + 1;
		$store_vote_up = "UPDATE $wpdb->posts SET vote_up = '$new_votes' WHERE ID = $pid";
		$upd_vote_up = $wpdb->query( $store_vote_up ) ;	
	}elseif( $act == 'down' ) {
		$new_votes = $vote_down + 1;	
		$store_vote_down = "UPDATE $wpdb->posts SET vote_down = '$new_votes' WHERE ID = $pid";
		$upd_vote_down = $wpdb->query( $store_vote_down );
	}
	
	// everything OK?
	if( $upd_vote_up || $upd_vote_down) {		
		// handle cookies
		setcookie( "zdm[$cook_str]", "Y", $cookiespan, '/' );
		echo $new_votes;		
	}	
}
?>